package com.itjiange.config;

import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import com.wf.captcha.servlet.CaptchaServlet;
import com.wf.captcha.utils.CaptchaUtil;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证码
 *
 * @author ItJiange
 * @date 2023/10/17
 */
@WebServlet("/captcha")
public class CaptchaConfig extends CaptchaServlet {
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        SpecCaptcha specCaptcha = new SpecCaptcha();
//        specCaptcha.setCharType(Captcha.TYPE_ONLY_NUMBER);

        GifCaptcha captcha = new GifCaptcha(130, 48);

//        ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
//        captcha.setLen(3);  // 几位数运算，默认是两位
//        captcha.getArithmeticString();  // 获取运算的公式：3+2=?
        CaptchaUtil.out(captcha, request, response);
        System.out.println("打印验证码");
    }
}
